package com.android.home.fragment;

import android.view.ViewGroup;
import com.android.common.base.rv.BaseRvAdapter;
import com.android.common.base.rv.BaseRvFragment;
import com.android.common.base.rv.BaseRvHolder;
import com.android.home.R;
import com.android.home.adapter.holder.LayerListHolder;
import com.android.home.mvp.model.home.LayerListBean;
import com.android.home.mvp.present.home.HomePresent;

public class LayerListFragment extends BaseRvFragment {

    private HomePresent present;

    @Override
    protected void onInitView() {
        super.onInitView();
        present = new HomePresent(this);
    }

    @Override
    protected BaseRvAdapter initAdapter() {
        BaseRvAdapter adapter = new BaseRvAdapter(getContext()) {

            @Override
            protected BaseRvHolder<LayerListBean.RowsBean> createDataViewHolder(ViewGroup parent, int viewType) {
                return new LayerListHolder(mLayoutInflater.inflate(R.layout.item_layer_list, parent, false));
            }
        };
        return adapter;
    }

    @Override
    protected boolean onNeedToolBar() {
        return false;
    }

    @Override
    protected void onLoadData() {
        super.onLoadData();
        showProgress();
        present.getLayerList();
    }

    @Override
    public void onSucceed(Object obj, String methodName) {
        super.onSucceed(obj,methodName);
        if (HomePresent.GET_LAYER_LIST.equals(methodName)){
            LayerListBean bean = (LayerListBean)obj;
            refreshOrLoadSuccess(bean.getRows(),bean.getTotal());
        }
    }
}
